#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>

int main() {
    int n = 0;
    int count = 0;

    while (~scanf("%d", &n))
    {
        for (int i = 0; i <= n; i++)
        {
            int sum = i * i;
            if (sum % 10 == i ||
                sum % 100 == i ||
                sum % 1000 == i ||
                sum % 10000 == i)
            {
                count++;
            }
        }
        printf("%d\n", count);
    }
    return 0;
}